<template>
  <div>
    <el-form :model="fromDate" :rules="rules">
      <el-form-item label="手机号" prop="user">
        <el-input v-model.trim="fromDate.user" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="fromDate.password" />
      </el-form-item>
      <el-form-item label="再次输入密码" prop="checkPass">
        <el-input v-model="fromDate.checkPass" />
      </el-form-item>
      <el-form-item>
        <el-button>登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    const checkPassWord = (rule, val, callback) => {
      const isPass = val === this.fromDate.password
      if (isPass) {
        callback()
      } else {
        callback(new Error('两次密码必须一致'))
      }
    }
    return {
      fromDate: {
        user: '',
        password: '',
        checkPass: ''
      },
      rules: {
        user: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1[3|4|5|7|8][0-9]{9}$/, message: '请输入正确手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 12, message: '密码长度为6-12个字符', trigger: 'blur' }
        ],
        checkPass: [
          { required: true, message: '请再次输入密码', trigger: 'blur' },
          { validator: checkPassWord, trigger: 'blur' }
        ]
      }
    }
  }
}
</script>

<style>

</style>
